#include "UIBar.h"

// Initialize the instance to null
UIBar* UIBar::m_UIBarInstance = 0;

UIBar::UIBar(void)
{
}

UIBar::~UIBar(void)
{
}

UIBar* UIBar::GetInstance(void)
{
	// Create the singleton if it doesn't exist
	if(!m_UIBarInstance)
		m_UIBarInstance = new UIBar;

	// Return the singleton
	return m_UIBarInstance;
}

void UIBar::DeleteUIBarInstance(void)
{
	// If instance exist, delete it!
	if(m_UIBarInstance)
	{
		delete m_UIBarInstance;
		m_UIBarInstance = NULL;
	}
}

void UIBar::Initialize(void)
{
	// Get the instance and initialize the sprite manager
	m_pSpriteManager = SpriteManager::GetInstance();
}

void UIBar::LoadUIBar(short sShieldLevel)
{
	// Create UI Sprites
	sUIBar = m_pSpriteManager->LoadSprite("UISprites\\UIBar.png", D3DXVECTOR3(511, 690, 0), 1.02f);
	sStraightTrackButton = m_pSpriteManager->LoadSprite("UISprites\\straightTrack.png", D3DXVECTOR3(845, 617, 0), 0.6f);
	sCurveTrackButton = m_pSpriteManager->LoadSprite("UISprites\\curveTrack.png", D3DXVECTOR3(745, 617, 0), 0.6f);
	sUndo = m_pSpriteManager->LoadSprite("UISprites\\undoLastButton.png", D3DXVECTOR3 (945, 617, 0), 0.6f);
	sUndoAll = m_pSpriteManager->LoadSprite("UISprites\\undoAllButton.png", D3DXVECTOR3 (945, 717, 0), 0.6f);
	/*sRedOrbButton = m_pSpriteManager->LoadSprite("UISprites\\redOrb.png", D3DXVECTOR3(820, 717, 0), 0.6f);
	sWhiteOrbButton = m_pSpriteManager->LoadSprite("UISprites\\whiteOrb.png", D3DXVECTOR3(720, 717, 0), 0.6f);
	sBlueOrbButton = m_pSpriteManager->LoadSprite("UISprites\\blueOrb.png", D3DXVECTOR3(920, 717, 0), 0.6f);
	sButtonX1 = m_pSpriteManager->LoadSprite("UISprites\\buttonX.png", D3DXVECTOR3(720, 717, 0), 0.6f);
	sButtonX2 = m_pSpriteManager->LoadSprite("UISprites\\buttonX.png", D3DXVECTOR3(820, 717, 0), 0.6f);
	sButtonX3 = m_pSpriteManager->LoadSprite("UISprites\\buttonX.png", D3DXVECTOR3(920, 717, 0), 0.6f);*/
	if(sShieldLevel >= 1)
	{
		sShield1 = m_pSpriteManager->LoadSprite("UISprites\\shieldPowerBar.png", D3DXVECTOR3(240, 685, 0), 0.8f);
	}
	if(sShieldLevel >= 2)
	{
		sShield2 = m_pSpriteManager->LoadSprite("UISprites\\shieldPowerBar.png", D3DXVECTOR3(300, 685, 0), 0.8f);
	}
	if(sShieldLevel >= 3)
	{
		sShield3 = m_pSpriteManager->LoadSprite("UISprites\\shieldPowerBar.png", D3DXVECTOR3(360, 685, 0), 0.8f);
	}
	sMaxSprite = m_pSpriteManager->LoadSprite("UISprites\\energyOrb.png", D3DXVECTOR3(520, 680, 0), 0.9f);
	sPause = m_pSpriteManager->LoadSprite("UISprites\\pauseLabel.png", D3DXVECTOR3(470, 200, 0), 1.0f);
}

void UIBar::Update(HWND hWnd, DirectInput* m_pDirectInput)
{
}

void UIBar::Render(void)
{
	for(int i = sUIBar; i <= sMaxSprite; i++)
			m_pSpriteManager->DrawSprite(i);
}

void UIBar::RenderPause(void)
{
	// Draw the pause menu
	m_pSpriteManager->DrawSprite(sPause); 
}

//void UIBar::SetSwitchXFlight(void)
//{
//	m_pSpriteManager->ModifySpritePos(sButtonX1, 820, 617);
//	m_pSpriteManager->ModifySpritePos(sButtonX2, 720, 617);
//	m_pSpriteManager->ModifySpritePos(sButtonX3, 920, 900);
//}
//
//void UIBar::SetSwitchXBuild(void)
//{
//	m_pSpriteManager->ModifySpritePos(sButtonX1, 720, 717);
//	m_pSpriteManager->ModifySpritePos(sButtonX2, 820, 717);
//	m_pSpriteManager->ModifySpritePos(sButtonX3, 920, 717);
//}

void UIBar::DestroyUI(void)
{
	for(short i = sPause; i >= sUIBar; i--)
		m_pSpriteManager->DestroySprite(i);
}